﻿/*去掉字符串空格*/
function trim(str) {
	if ((str.indexOf(" ") == -1) && (str.indexOf("　") == -1)) {
		return (str);
	}
	var _local5 = str;
	str = replace(str, "　", " ");
	var _local3 = 0;
	var _local4 = 0;
	var _local2 = 0;
	while (_local2<str.length) {
		if (str.charAt(_local2) != " ") {
			break;
		} else {
			_local3++;
		}
		_local2++;
	}
	_local2 = str.length-1;
	while (_local2>0) {
		if (str.charAt(_local2) != " ") {
			break;
		} else {
			_local4++;
		}
		_local2--;
	}
	return (_local5.substring(_local3, _local5.length-_local4));
}

function replace(s, o, n) {
	s = s.split(o).join(n);
	return (s);
}


/*加载CSS样式，设置CSS样式*/
var _globalCSS = (new TextField.StyleSheet());
function loadCSS(url) {
	_globalCSS.onLoad = function(success) {
		if (success) {
			/*function();*/
		} else {
			trace(("css file [ "+url)+" ] doesn't exist.");
		}
	};
	_globalCSS.load(url);
}
loadCSS("global.css");
/*setGlobalCSS([thumb.title], _globalCSS);[thumb.title]为动态文本*/
function setGlobalCSS(arr, css) {
	var _local1;
	for (_local1 in arr) {
		if (arr[_local1] instanceof TextField) {
			arr[_local1].html = true;
			arr[_local1].styleSheet = css;
		}
	}
}

/*获取文件名后缀名*/
/*getFileInfo("1.jpg", "fileNamePostfix") != "flv"*/
function getFileInfo(path, part) {
	var _local1 = {};
	var _local3 = "\\";
	if ((path.indexOf("\\") == -1) && (path.indexOf("/") != -1)) {
		_local3 = "/";
	}
	_local1.meta = path;
	_local1.path = path.substring(0, path.lastIndexOf(_local3)+1);
	_local1.fileName = path.substring(path.lastIndexOf(_local3)+1);
	_local1.fileNamePrefix = _local1.fileName.substring(0, _local1.fileName.lastIndexOf("."));
	_local1.fileNamePostfix = _local1.fileName.substring(_local1.fileName.lastIndexOf(".")+1);
	if ((part != "") && (part != undefined)) {
		return (_local1[part]);
	} else {
		return (_local1);
	}
}

/*16进制转换成10进制*/
function intoNumber(s) {
	return (Number(replace(s, "#", "0x")));
}
function replace(s, o, n) {
	s = s.split(o).join(n);
	return (s);
}

/*获取数组最大最小值*/
var array = new Array("0", "1", "2", "3", "4");
function getMin(arr) {
	arr.sort();
	return (arr[0]);
}
function getMax(arr) {
	arr.sort();
	return (arr[arr.length-1]);
}

//获得两数之间的随机数。
function rangeRandom(min, max) {
	var _local2 = max-min;
	var _local1 = (Math.random()*_local2)+min;
	return (Math.ceil(_local1));
}
/*获取三数之间的中间值*/
function clamp(min, n, max) {
	if (min>max) {
		var _local3 = max;
		max = min;
		min = _local3;
	}
	if (n<min) {
		return (min);
	}
	if (n>max) {
		return (max);
	}
	return (n);
}
trace(clamp(1, 9, 5));
/*n和min,max比较，大就取小，小就取大*/
function loopNumber(min, n, max) {
	if (min>max) {
		var _local3 = max;
		max = min;
		min = _local3;
	}
	if (n<min) {
		return (max);
	}
	if (n>max) {
		return (min);
	}
	return (n);
}
/*等比scale缩放*/
function setScaleFull(targetMc, boxWidth, boxHeight) {
	targetMc.imagebox._xscale = 100;
	targetMc.imagebox._yscale = 100;
	var _local4 = targetMc.imagebox._width/targetMc.imagebox._height;
	var _local3 = boxWidth/boxHeight;
	var _local2 = 100;
	if (_local3<1) {
		if (_local3<=_local4) {
			_local2 = (boxHeight*100)/targetMc.imagebox._height;
		} else {
			_local2 = (boxWidth*100)/targetMc.imagebox._width;
		}
	} else if (_local3<=_local4) {
		_local2 = (boxHeight*100)/targetMc.imagebox._height;

	} else {
		_local2 = (boxWidth*100)/targetMc.imagebox._width;
	}
	targetMc.imagebox._xscale = _local2;
	targetMc.imagebox._yscale = _local2;
}
//设置MC颜色
function setRGB(mc, color) {
	var _local1 = new flash.geom.ColorTransform();
	_local1.rgb = color;
	var _local2 = new flash.geom.Transform(mc);
	_local2.colorTransform = _local1;
}
setRGB(aa,0x333333)

